from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime

class InitUploadRequest(BaseModel):
    """初始化上传请求模型"""
    file_name: str = Field(..., description="文件名称")
    file_size: int = Field(..., description="文件总大小(字节)")
    chunk_size: int = Field(..., description="分片大小(字节)")
    mime_type: Optional[str] = Field(None, description="MIME类型")
    directory_id: int = Field(0, description="目标目录ID，0表示根目录")
    
class InitUploadResponse(BaseModel):
    """初始化上传响应模型"""
    task_id: str = Field(..., description="上传任务ID")
    upload_id: str = Field(..., description="MinIO上传ID")
    chunk_size: int = Field(..., description="分片大小(字节)")
    total_chunks: int = Field(..., description="总分片数")
    expires_at: datetime = Field(..., description="任务过期时间")

class ChunkUploadRequest(BaseModel):
    """分片上传请求模型"""
    task_id: str = Field(..., description="上传任务ID")
    chunk_number: int = Field(..., description="分片序号(从1开始)")
    
class ChunkUploadResponse(BaseModel):
    """分片上传响应模型"""
    task_id: str = Field(..., description="上传任务ID")
    chunk_number: int = Field(..., description="分片序号")
    etag: str = Field(..., description="分片ETag")
    uploaded_chunks: int = Field(..., description="已上传分片数")
    total_chunks: int = Field(..., description="总分片数")
    
class CompleteUploadRequest(BaseModel):
    """完成上传请求模型"""
    task_id: str = Field(..., description="上传任务ID")
    
class UploadStatusRequest(BaseModel):
    """上传状态查询请求模型"""
    task_id: str = Field(..., description="上传任务ID")
    
class ChunkInfo(BaseModel):
    """分片信息模型"""
    chunk_number: int = Field(..., description="分片序号")
    status: str = Field(..., description="分片状态")
    
class UploadStatusResponse(BaseModel):
    """上传状态响应模型"""
    task_id: str = Field(..., description="上传任务ID")
    file_name: str = Field(..., description="文件名称")
    file_size: int = Field(..., description="文件总大小(字节)")
    status: str = Field(..., description="任务状态")
    uploaded_chunks: int = Field(..., description="已上传分片数")
    total_chunks: int = Field(..., description="总分片数")
    progress: float = Field(..., description="上传进度(0-100)")
    chunks: List[ChunkInfo] = Field(..., description="分片状态列表")
    create_time: datetime = Field(..., description="任务创建时间")
    update_time: datetime = Field(..., description="任务更新时间")
    expires_at: datetime = Field(..., description="任务过期时间")
    
    class Config:
        """Pydantic配置"""
        from_attributes = True 